package com.ys.util;

import java.math.BigDecimal;
import java.math.BigInteger;

public class HexUtil {

    public static BigInteger hexToBigInteger(String hex){
        return new BigInteger(hex.toUpperCase().replace("0X",""),16);

    }

/*    public static double hexToDouble(String hex){
        Double.i
        return new Double(hex.toUpperCase().replace("0X",""),16);

    }*/
    public static Integer hexToInteger(String hex){
        return  Integer.valueOf(hex.toUpperCase().replace("0X",""),16);

    }
    public  static String doubleToHex(Double d){
       return "0x"+Double.toHexString(d);

    }
    public  static String integerToHex(Integer num){
        return "0x"+Integer.toHexString(num);

    }

    public  static String bigintegerToHex(BigInteger num){
        return "0x"+num.toString(16);

    }

    public static void main(String[] args) {
        //System.out.printf(hexToBigInteger("0x1.9d81d96p36")+"============");
        System.out.println(bigintegerToHex(new BigDecimal("4222222222222222222222222").toBigInteger())+"");
        System.out.println(bigintegerToHex(new BigInteger("42222222222223333333333322"))+"");
        System.out.println((new BigDecimal("4222222222222222222222222")).toBigInteger().toString()+"");
        //0xde0b6b3a75d9760  0x668a0 0x430e23400

        System.out.println(hexToBigInteger("0xde0b6b3a75d9760").add(hexToBigInteger("0x668a0")).toString());
        System.out.println(hexToBigInteger("0x430e23400"));
        System.out.println(hexToBigInteger("0x668a0"));
        System.out.println(hexToBigInteger("0xdc5daebfce38000"));
    }
}
